package com.youcan.search;


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.solr.client.solrj.SolrServer;

/**
 * 获取SolrServer实例的工厂类。
 * 
 */
public class SolrServerFactory {
	
	private static Map<String, SolrServer> searchServerMap = Collections
			.synchronizedMap(new HashMap<String, SolrServer>());

	/**
	 * 根据一个solr core名取得SolrServer实例。
	 * 
	 * @param coreName solr core的名称
	 * @return SolrServer实例
	 */
	public SolrServer getSolrServer(String coreName) {
		SolrServer solrServer = null;
		if (!searchServerMap.containsKey(coreName)) {
			solrServer = SolrServerWrapper.getSolrServer(coreName);
			if (solrServer != null)
				searchServerMap.put(coreName, solrServer);
		}
		return searchServerMap.get(coreName);
	}
}